.\"
.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
.\" permission to reproduce portions of its copyrighted documentation.
.\" Original documentation from The Open Group can be obtained online at
.\" http://www.opengroup.org/bookstore/.
.\"
.\" The Institute of Electrical and Electronics Engineers and The Open
.\" Group, have given us permission to reprint portions of their
.\" documentation.
.\"
.\" In the following statement, the phrase ``this text'' refers to portions
.\" of the system documentation.
.\"
.\" Portions of this text are reprinted and reproduced in electronic form
.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
.\" Standard for Information Technology -- Portable Operating System
.\" Interface (POSIX), The Open Group Base Specifications Issue 6,
.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
.\" Engineers, Inc and The Open Group.  In the event of any discrepancy
.\" between these versions and the original IEEE and The Open Group
.\" Standard, the original IEEE and The Open Group Standard is the referee
.\" document.  The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
.\" This notice shall appear on any product containing this material.
.\"
.\" The contents of this file are subject to the terms of the
.\" Common Development and Distribution License (the "License").
.\" You may not use this file except in compliance with the License.
.\"
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
.\" or http://www.opensolaris.org/os/licensing.
.\" See the License for the specific language governing permissions
.\" and limitations under the License.
.\"
.\" When distributing Covered Code, include this CDDL HEADER in each
.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
.\" If applicable, add the following below this CDDL HEADER, with the
.\" fields enclosed by brackets "[]" replaced with your own identifying
.\" information: Portions Copyright [yyyy] [name of copyright owner]
.\"
.\"
.\" Copyright (c) 2001, The IEEE and The Open Group.  All Rights Reserved.
.\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved.
.\"
.TH PTHREAD_TESTCANCEL 3C "Mar 23, 2005"
.SH NAME
pthread_testcancel \- create cancellation point in the calling thread
.SH SYNOPSIS
.LP
.nf
cc -mt [ \fIflag\fR... ] \fIfile\fR... -lpthread [ \fIlibrary\fR... ]
#include <pthread.h>

\fBvoid\fR \fBpthread_testcancel\fR(\fBvoid\fR);
.fi

.SH DESCRIPTION
.sp
.LP
The \fBpthread_testcancel()\fR function forces testing for cancellation. This
is useful  when you need to execute code that runs for long periods without
encountering cancellation points; such as a library routine that executes
long-running computations without cancellation points. This type of code can
block cancellation for unacceptable long periods of time.   One strategy for
avoiding blocking cancellation for long periods, is to insert calls to
\fBpthread_testcancel()\fR in the long-running computation code and to setup a
cancellation handler in the library code, if required.
.SH RETURN VALUES
.sp
.LP
The \fBpthread_testcancel()\fR function returns \fBvoid\fR.
.SH ERRORS
.sp
.LP
The \fBpthread_testcancel()\fR function does not return errors.
.SH EXAMPLES
.sp
.LP
See \fBcancellation\fR(7) for an example of using \fBpthread_testcancel()\fR to
force testing for cancellation and a discussion of cancellation concepts.
.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(7) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	Standard
_
MT-Level	MT-Safe
.TE

.SH SEE ALSO
.sp
.LP
.BR Intro (3),
.BR pthread_cleanup_pop (3C),
.BR pthread_cleanup_push (3C),
.BR pthread_exit (3C),
.BR pthread_join (3C),
.BR pthread_setcancelstate (3C),
.BR pthread_setcanceltype (3C),
.BR setjmp (3C),
.BR attributes (7),
.BR cancellation (7),
.BR condition (7),
.BR standards (7)
.SH NOTES
.sp
.LP
The \fBpthread_testcancel()\fR function has no effect if cancellation is
disabled.
.sp
.LP
Use \fBpthread_testcancel()\fR with \fBpthread_setcanceltype()\fR called with
its \fIcanceltype\fR set to \fBPTHREAD_CANCEL_DEFERRED\fR. The
\fBpthread_testcancel()\fR function operation is undefined if
\fBpthread_setcanceltype()\fR was called with its \fIcanceltype\fR argument set
to \fBPTHREAD_CANCEL_ASYNCHRONOUS\fR.
.sp
.LP
It is possible to kill a thread when it is holding a resource, such as lock or
allocated memory. If that thread has not setup a cancellation cleanup handler
to release the held resource, the application is "cancel-unsafe".  See
\fBattributes\fR(7) for a discussion of Cancel-Safety, Deferred-Cancel-Safety,
and Asynchronous-Cancel-Safety.
